# coding=utf-8
from rest_framework.permissions import IsAdminUser
from rest_framework.response import Response
from rest_framework.views import APIView
from users.models import User
from datetime import date

class UserCounter(APIView):
    # 指定用户权限
    permission_classes = (IsAdminUser,)
    # 查询所有用户总量
    def get(self, request):
        count= User.objects.all().count()
    # 获取当前日期
        date_date = date.today()
    # 返回用户总量和当前日
        return Response({
            'count':count,
            'date':date_date
        })

class UserDayCounter(APIView):
    # 指定用户权限
    permission_classes = (IsAdminUser,)
    def get(self, request):
        # 获取当前日期
        date_date = date.today()
        # 获取当天注册的数量    gte >=
        count= User.objects.filter(date_joined__gte=date_date).count()
        # 返回用户总量和当前日
        return Response({
            'count':count,
            'date':date_date
        })



class UserDayActiveCounter(APIView):
    # 指定用户权限
    permission_classes = (IsAdminUser,)
    def get(self, request):
        # 获取当前日期
        date_date = date.today()
        # 获取当天注册的数量    gte >=
        count= User.objects.filter(last_login__gte=date_date).count()
        # 返回用户总量和当前日
        return Response({
            'count':count,
            'date':date_date
        })

class UserDayOrderCounter(APIView):
    # 指定用户权限
    permission_classes = (IsAdminUser,)
    def get(self, request):
        # 获取当前日期
        date_date = date.today()
        # 获取当前下单的数量  gte >=
        count= User.objects.filter(orders__create_time__gte=date_date).count()
        # 返回用户总量和当前日
        return Response({
            'count':count,
            'date':date_date
        })